<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>数据字典生成助手 -- 第二步</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
    <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
    <style type="text/css">
        body {
            background: #c0ffa7;
            color: #4f1b18;
        }

        .alert {
            text-align: center;
            margin-left: 150px;
        }

        .row {
            margin: 0 auto;
        }

        form {
            width: 90%;
        }

        #all {
            margin:15px 0 20px 0;
        }

        .box {
            border:1px solid #eee;
            border-radius:7px;
            height:400px;
            overflow-y: auto;
            background:#fff;
            padding:12px;
        }
    </style>
</head>
<body>
<div class="row">
    <h1 class="text-center">数据字典生成助手 -- 第二步</h1>
    <?php if (isset($error)): ?>
        <div class="alert alert-danger"><?php echo $error; ?></div>
    <?php endif; ?>
    <form class="form-horizontal" method="post" action="?step=3">
        <div class="form-group">
            <label for="ip" class="col-sm-2 control-label">选择数据库</label>
            <div class="col-sm-10">
                <select class="form-control" id="database">
                    <option value="-1"> --选择数据库-- </option>
                    <?php foreach($databases as $k=>$item):?>
                        <?php if(isset($_GET['database']) && $item == $_GET['database']): ?>
                            <option value="<?php echo $item;?>" selected="selected"><?php echo $item;?></option>
                        <?php else: ?>
                            <option value="<?php echo $item;?>"><?php echo $item;?></option>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
        <?php if(isset($_GET['database'])): ?>
        <div class="form-group">
            <label for="ip" class="col-sm-2 control-label">选择数据表</label>
            <div class="col-sm-10">
                <input type="checkbox" id="all"/>全选/反选
                <div class="box">
                    <?php foreach($tables as $k=>$item):?>
                        <input type="checkbox" name="tables[]" class="children" value="<?php echo $item; ?>"/> <?php echo $item; ?> <br />
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        <?php endif; ?>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-success btn-block">下一步</button>
            </div>
        </div>
        <input type="hidden" name="database" value="<?php echo $_GET['database']; ?>"/>
    </form>
</div>
<script>
    $('#database').change(function() {
        if($(this).val() != -1)
            window.location.href = '?step=2&database=' + $(this).val();
        else
            window.location.href = '?step=2';
    });
    var flag = true;
    $('#all').click(function() {
        if(flag)
        {
            $('.children').attr('checked', 'checked');
            flag = false;
        }
        else
        {
            $('.children').attr('checked', false);
            flag = true;
        }
    })
</script>
</body>
</html>